package sky.springboot.literature_and_art.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import sky.springboot.literature_and_art.pojo.PageBean;
import sky.springboot.literature_and_art.pojo.Article;
import sky.springboot.literature_and_art.pojo.Result;
import sky.springboot.literature_and_art.service.ArticleService;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Result add(@RequestBody @Validated Article article){
        articleService.add(article);
        return Result.success();
    }

    @GetMapping
    public Result<PageBean<Article>> list(Integer pageNum,
                                            Integer pageSize,
                                            @RequestParam(required = false) Integer categoryId,
                                            @RequestParam(required = false) String state){
        PageBean<Article> pb = articleService.list(pageNum,pageSize,categoryId,state);
        return Result.success(pb);
    }

}
